﻿using System.Linq;
using Avalon.Core.Data;
using Avalon.Core.Data.Templates;
using System;

namespace Avalon.Core.Providers {
    public class ViewProvider : BaseProvider, IViewProvider {

        public IViewDescriptor GetView() {

            IControllerDescriptor controllerDescriptor = ContextProvider.ControllerDescriptor;
            if (controllerDescriptor == null) throw new InvalidOperationException("Controller Descriptor can't be null.");

            IRendererDescriptor renderDescriptor = controllerDescriptor.RendererDescriptor;
            IEntityDescriptor entityDescriptor = controllerDescriptor.EntityDescriptor;


            AvalonEntity entity = RepositoryConfig.Initialize<AvalonEntity>().Get().FirstOrDefault(e => e.AssemblyQualifiedName == entityDescriptor.EntityType.AssemblyQualifiedName);
            if (entity != null) {
                AvalonViewRenderer renderer = RepositoryConfig.Initialize<AvalonViewRenderer>().Get().FirstOrDefault(vr => vr.Action == this.Action);
                IQueryable<AvalonView> views = RepositoryConfig.Initialize<AvalonView>().Get().Where(avalonView => avalonView.Entity.Id == entity.Id);
 
            }


            return null;
        }
    }
}
